package com.yixun.service.impl;

import com.yixun.entity.YxProNewVariety;
import com.yixun.entity.YxSurveyXqRecord;
import com.yixun.mapper.YxProNewVarietyMapper;
import com.yixun.service.YxProNewVarietyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 畜禽品种管理(YxProNewVariety)表服务实现类
 *
 * @author lbx
 * @since 2021-06-16 15:42:41
 */
@Service("yxProNewVarietyService")
public class YxProNewVarietyServiceImpl implements YxProNewVarietyService {
    @Resource
    private YxProNewVarietyMapper yxProNewVarietyMapper;
    
    /**
     * 通过ID查询单条数据
     *
     * @param newVarietyId 主键
     * @return 实例对象
     */
    @Override
    public YxProNewVariety queryById(Long newVarietyId) {
        return this.yxProNewVarietyMapper.queryById(newVarietyId);
    }
    
    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<YxProNewVariety> queryAllByLimit(int offset, int limit) {
        return this.yxProNewVarietyMapper.queryAllByLimit(offset, limit);
    }
    
    /**
     * 新增数据
     * @param yxProNewVariety 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(YxProNewVariety yxProNewVariety) {
        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        yxProNewVariety.setAddTime(date);
        return this.yxProNewVarietyMapper.insert(yxProNewVariety);
    }
    
    /**
     * 修改数据
     *
     * @param yxProNewVariety 实例对象
     * @return 实例对象
     */
    @Override
    public YxProNewVariety update(YxProNewVariety yxProNewVariety) {
        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        yxProNewVariety.setUpdateTime(date);
        this.yxProNewVarietyMapper.update(yxProNewVariety);
        return this.queryById(yxProNewVariety.getNewVarietyId());
    }
    
    /**
     * 通过主键删除数据
     *
     * @param newVarietyId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long newVarietyId) {
        return this.yxProNewVarietyMapper.deleteById(newVarietyId) > 0;
    }
    
    @Override
    public int updateIsDelete(HashMap<String, Object> map) {
        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        map.put("updateTime",date);
        return yxProNewVarietyMapper.updateIsDelete(map);
    }
    
    @Override
    public Integer getCount() {
        return yxProNewVarietyMapper.getCount();
    }
    
    @Override
    public String getNameById(Integer newVarietyId) {
        return yxProNewVarietyMapper.getNameById(newVarietyId);
    }
    
    @Override
    public List<YxProNewVariety> queryAll() {
        return yxProNewVarietyMapper.queryAll(0);
    }
    
    @Override
    public List<YxSurveyXqRecord> searchAll(HashMap<String, Object> map) {
        return yxProNewVarietyMapper.searchAll(map);
    }
    
    @Override
    public int getSearchCount(HashMap<String, Object> map) {
        return yxProNewVarietyMapper.getSearchCount(map);
    }
}
